package cn.itsource.pethome.basic.util;

import cn.itsource.pethome.user.domain.User;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;

public class UserContext {

    /**
     * 获取当前登录用户（前端用户）
     * @return
     */
    public static User getLoginUser(HttpServletRequest request){
        //获取token值
        String token = request.getHeader("U-TOKEN");
        //获取用户的json字符串
        String userJsonInfo = RedisUtils.INSTANCE.get(token);
        //把json字符串转为JSON对象
        User user = JSONObject.parseObject(userJsonInfo, User.class);
        return user;
    }

}
